/*
  学习目标：React声明周期-卸载阶段-挂载定时器，并且卸载
*/

import React, { Component } from 'react';

export default class App extends Component {
  state = {
    showChild: true,
  };
  render() {
    return (
      <div>
        我是父组件
        {this.state.showChild && <Child></Child>}
      </div>
    );
  }
}

class Child extends React.Component {
  timerId = -1;

  componentDidMount() {
    this.timerId = setInterval(() => {
      console.log(123);
    }, 100);
  }

  render() {
    return <div>我是子组件</div>;
  }

  componentWillUnmount() {
    //  清除定时器、解除事件监听
    clearInterval(this.timerId);
  }
}
